/**
 * 路由控制层
 */
const express = require('express')
const router = express.Router()
const BlogDao = require('../model/BlogDao')


//首页
router.get('/login', (req, res) => {
    res.render('home/login.html', {})
})
router.post('/login', (req, res) => {

    BlogDao.LoginUser([req.body.emil, req.body.pwd], e => {
        if (e.length != 0) {
            req.session.admin = e
            res.redirect('/admin')
        } else {
            res.render('home/login.html', {
                flag: '密码错误'
            })
        }

    })
})

router.get('/register', (req, res) => {
    res.render('home/register.html', {})

})

router.post('/reginsert', (req, res) => {
    res.render('home/register.html', {})
})

router.get('/outlogin', (req, res) => {
    req.session.destroy(function(err) {
        res.redirect('/');
    })
})


//导出路由
module.exports = router;